<?php 


include 'vendor\autoload.php';

use mikehaertl\wkhtmlto\Pdf;

// You can pass a filename, a HTML string, an URL or an options array to the constructor
$pdf = new Pdf('E:\work\xampp\body\htdocs\laravelBeginner\baidu.html');


// On some systems you may have to set the path to the wkhtmltopdf executable
$pdf->binary = 'E:\work\pycharm\wkhtmltopdf.exe';


if (!$pdf->saveAs('E:\work\xampp\body\htdocs\laravelBeginner\baidu.pdf')) {
    $error = $pdf->getError();
	print_r($error);
    // ... handle error here
}

echo "over";
die();


function doGet($url='', $opt = []) {

    if (!$url) {
       $url = $this->url;
    }

    $ch = curl_init();
    $timeout = 5;

    // 发送数据
//    $POST_DATA = $opt['getData'] ?? [];
    if ($this->getData) {
       $this->finalUrl = $url . "?" . http_build_query($this->getData);
    }

    // 模拟浏览器
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
       'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
       'Connection: keep-alive',
       'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36',
       //    'Accept-Encoding: gzip, deflate, br',
       'Accept-Language: zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7',
    ));
    
    // オレオレ証明書対策
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  //
    // 跟随302
// //    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    // if (($opt['getCookie'] ?? false) || $this->isGetCookie) {
    //    // set cookie
    //    curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiePath);
    // }
    // if (($opt['setCookie'] ?? false) || $this->isSetCookie) {
    //    // get cookie
    //    curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiePath);
    // }

    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    $file_contents = curl_exec($ch);
    $info = curl_getinfo($ch);

    // ヘッダ部分を取得
    $this->responseHeader = substr($file_contents, 0, $info["header_size"]);

    $this->parseHeader();
    // ボディ部分を取得
    $this->responseBody = substr($file_contents, $info["header_size"]);

    if (curl_error($ch)) {
       echo curl_error($ch);
    }else {
    }
    curl_close($ch);

    return $this->responseBody;
 }
